package com.haixiaoke.business;

import com.haixiaoke.common.annotation.Log;
import com.haixiaoke.common.core.domain.AjaxResult;
import com.haixiaoke.common.core.page.TableDataInfo;
import com.haixiaoke.common.enums.BusinessType;
import com.haixiaoke.common.utils.poi.ExcelUtil;
import com.haixiaoke.domain.LockInfoLog;
import com.haixiaoke.service.ILockInfoLogService;
import com.haixiaoke.system.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 智能锁锁信息上报日志(心跳日志)Controller
 *
 * @author qixi
 * @date 2023-05-30
 */
@RestController
@RequestMapping("/business/lockInfoLog")
public class LockInfoLogController extends BaseController {
    @Autowired
    private ILockInfoLogService lockInfoLogService;

    /**
     * 查询智能锁锁信息上报日志列表
     */
    @PreAuthorize("@ss.hasPermi('business:lockInfoLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(LockInfoLog lockInfoLog) {
        startPage();
        List<LockInfoLog> list = lockInfoLogService.selectLockInfoLogList(lockInfoLog);
        return getDataTable(list);
    }

    /**
     * 导出智能锁锁信息上报日志列表
     */
    @PreAuthorize("@ss.hasPermi('business:lockInfoLog:export')")
    @Log(title = "智能锁锁信息上报日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LockInfoLog lockInfoLog) {
        List<LockInfoLog> list = lockInfoLogService.selectLockInfoLogList(lockInfoLog);
        ExcelUtil<LockInfoLog> util = new ExcelUtil<LockInfoLog>(LockInfoLog.class);
        util.exportExcel(response, list, "智能锁锁信息上报日志数据");
    }

    /**
     * 获取智能锁锁信息上报日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:lockInfoLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(lockInfoLogService.selectLockInfoLogById(id));
    }

    /**
     * 新增智能锁锁信息上报日志
     */
    @PreAuthorize("@ss.hasPermi('business:lockInfoLog:add')")
    @Log(title = "智能锁锁信息上报日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LockInfoLog lockInfoLog) {
        return toAjax(lockInfoLogService.insertLockInfoLog(lockInfoLog));
    }

    /**
     * 修改智能锁锁信息上报日志
     */
    @PreAuthorize("@ss.hasPermi('business:lockInfoLog:edit')")
    @Log(title = "智能锁锁信息上报日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LockInfoLog lockInfoLog) {
        return toAjax(lockInfoLogService.updateLockInfoLog(lockInfoLog));
    }

    /**
     * 删除智能锁锁信息上报日志
     */
    @PreAuthorize("@ss.hasPermi('business:lockInfoLog:remove')")
    @Log(title = "智能锁锁信息上报日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(lockInfoLogService.deleteLockInfoLogByIds(ids));
    }
}
